package pw.hais.etgsh.dao;

import org.json.JSONObject;

import java.util.HashMap;
import java.util.Map;

import pw.hais.app.UtilConfig;
import pw.hais.etgsh.app.V;
import pw.hais.etgsh.entity.MessageEntity;
import pw.hais.etgsh.model.CheckAPPModel;
import pw.hais.etgsh.model.LeadModel;
import pw.hais.http.Http;
import pw.hais.http.base.OnHttpListener;
import pw.hais.utils.EmptyUtil;

/**
 * LeadCloud平台
 * Created by Hais1992 on 2015/12/18.
 */
public class LeadDao {

    public static Map<String, String> header = new HashMap<>();

    static {
        header.put("X-LC-Id", V.X_LC_Id);
        header.put("X-LC-Key", V.X_LC_Key);
    }

    public static void checkAPPVersion(OnHttpListener<CheckAPPModel> listener){
        Http.get(V.LEAD_SERVER_URL+"/classes/AppFile/"+V.APP_File_ID,header,null,listener);
    }


    /**
     * 发布留言
     * @param messageEntity
     * @param listener
     */
    public static void postFeedback(MessageEntity messageEntity,OnHttpListener<LeadModel> listener){
       try {
           JSONObject jsonObject = new JSONObject(UtilConfig.GSON.toJson(messageEntity));
           Http.post(V.LEAD_SERVER_URL + "/classes/Message", header, null, jsonObject, listener);
       }catch (Exception e){e.printStackTrace();}
    }

}
